/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonybeans;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.Stateless;

/**
 *
 * @author 4410s
 */
@Stateless
public class Change_Password_Admin implements Change_Password_AdminLocal {
    Connection conn;
    ResultSet rs=null;
    @Override
    public ResultSet Select_Admin_data(String username_admin) {
        try {
            ConnectDB conDB = new ConnectDB();
               conn = conDB.getConnection();
               String strSql = "SELECT * from Adminitrator where username_admin=? ";
               PreparedStatement pstmt = conn.prepareStatement(strSql);
               pstmt.setString(1,username_admin );
               
               rs = pstmt.executeQuery();
           
        } catch (SQLException ex) {
            Logger.getLogger(Change_Password_Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
        return rs;
    }

    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
boolean flag=false;
    @Override
    public Boolean Change_Pass_Admin(String password,String username_admin) {
        try {
            ConnectDB conDB = new ConnectDB();
                conn = conDB.getConnection();
                String strSql_update = "Update  Adminitrator set password=? where username_admin=? ";
                PreparedStatement pstmt_update = conn.prepareStatement(strSql_update);
                
                pstmt_update.setString(1, password);
                pstmt_update.setString(2,username_admin);
                int count=0;
                count= pstmt_update.executeUpdate();
                if (count>0) {
                    flag=true;
                }else
                {
                    flag=false;
                }
           
        } catch (SQLException ex) {
            Logger.getLogger(Change_Password_Admin.class.getName()).log(Level.SEVERE, null, ex);
        }
         return flag;
    }
    

}
